package com.zoweunion.mechanic.plugins.shiro;

import com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.annotation.PostConstruct;
import java.util.List;

@Configurable
@AutoConfigureBefore(PageHelperAutoConfiguration.class)
public class DataRangMyBatisInterceptorAutoConfiguration {
    @Autowired
    private List<SqlSessionFactory> sqlSessionFactoryList;

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @PostConstruct
    public void addMyInterceptor() {
        DataRangMyBatisInterceptor e = new DataRangMyBatisInterceptor(jdbcTemplate);
        for (SqlSessionFactory sqlSessionFactory : sqlSessionFactoryList) {
            sqlSessionFactory.getConfiguration().addInterceptor(e);
        }
    }
}
